#include "weatherdisplaybox.h"

WeatherDisplayBox::WeatherDisplayBox(QWidget *parent)
    : QWidget(parent)
{
    // 设定默认颜色
    color = QColor (255, 255, 255);
    QVBoxLayout *vbox_layout=new QVBoxLayout(this);
    weekday_label=new QLabel();
    // weekday_label->setText("星期一");
    weatherPixmap_label=new QLabel();
    weatherPixmap_label->setScaledContents(true);
    // weatherPixmap_label->setPixmap(QPixmap(":/多云转晴"));
    wendu_label=new QLabel();
    // wendu_label->setText("29℃ 29℃");
    vbox_layout->addWidget(weekday_label);
    vbox_layout->addWidget(weatherPixmap_label);
    vbox_layout->addWidget(wendu_label);
}

WeatherDisplayBox::~WeatherDisplayBox()
{
    
}

void WeatherDisplayBox::set_color(QColor color)
{
    this->color = color;
}

void WeatherDisplayBox::set_weekday_label(QString week)
{
    weekday_label->setText(week);
}

void WeatherDisplayBox::set_weatherPixmap_label(QPixmap pixmap)
{
    weatherPixmap_label->setPixmap(pixmap);
}

void WeatherDisplayBox::set_wendu_label(QString lower,QString high)
{
    wendu_label->setText(lower+"℃ "+high+"℃");
}
void WeatherDisplayBox::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    
    // 创建 QPainter 对象
    QPainter painter(this);
    
    // 启用抗锯齿效果，使绘制更加平滑
    painter.setRenderHint(QPainter::Antialiasing);
    
    // 设置画笔颜色和宽度
    QPen pen;
    pen.setColor(this->color);  // 设置边框颜色为黑色
    pen.setWidth(0);  // 设置边框宽度
    painter.setPen(pen);
    
    // 设置画刷颜色
    QBrush brush;
    brush.setColor(this->color);  // 设置填充颜色为浅蓝色
    brush.setStyle(Qt::SolidPattern);
    painter.setBrush(brush);
    
    // 获取控件的矩形区域
    QRect rect = this->rect();
    
    // 绘制圆角矩形，rect 是控件的区域，设置圆角半径为 15
    painter.drawRoundedRect(rect, 15, 15);
}
